package springcloud.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.yxt.springcloud.entities.CommonResult;

@RestController
@RequestMapping(value = "sentinel")
public class SentinelPaymentController {

    @Value("${server.port}")
    private int port;

    @GetMapping(value = "payment")
    public CommonResult payment() {
        return new CommonResult(1, "this is sentinel payment", "端口: " + port);
    }

    /**
     * 这里预留一个错误异常漏洞。当number=0时候会出现错误。客户端尅激活降级
     *
     * @param number
     * @return
     */
    @GetMapping(value = "fallback/{number}")
    public CommonResult fallback(@PathVariable int number) {
        return new CommonResult(1, "当前服务端口 " + port, "计算结果为：" + (10 / number));
    }
}
